package com.fly.controller.manage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fly.component.result.CommonResult;
import com.fly.entity.${modelNameUpperCamel};
import com.fly.service.${modelNameUpperCamel}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ${remarks}后台管理控制层
 *
 * @author ${author}
 * @date ${date}
 */
@RestController
@Api(tags = "${remarks}")
@RequestMapping("api/${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {

    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @ApiOperation("添加${remarks}")
    @PostMapping(value = "/create")
    public CommonResult create(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.create(${modelNameLowerCamel});
        return CommonResult.success();
    }

    @ApiOperation("删除${remarks}")
    @PostMapping(value = "/delete/{id}")
    public CommonResult deleteById(@PathVariable Long id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return CommonResult.success();
    }

    @ApiOperation("批量删除${remarks}")
    @PostMapping(value = "/batchDelete")
    public CommonResult batchDeleteByIds(List<Long> ids) {
    ${modelNameLowerCamel}Service.batchDeleteByIds(ids);
        return CommonResult.success();
    }

    @ApiOperation("修改${remarks}")
    @PostMapping(value = "/update/{id}")
    public CommonResult update(@PathVariable Long id,@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.update(id,${modelNameLowerCamel});
        return CommonResult.success();
    }

    @ApiOperation("分页查询${remarks}")
    @GetMapping(value = "/list")
    public CommonResult<Page<${modelNameUpperCamel}>> fetchList( @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return CommonResult.success(${modelNameLowerCamel}Service.fetchList(pageNum,pageSize,${modelNameLowerCamel}));
    }

    @ApiOperation("获取单个${remarks}")
    @GetMapping(value = "/list/{id}")
    public CommonResult<${modelNameUpperCamel}> fetchDetail(@PathVariable Long id) {
        ${modelNameUpperCamel} details = ${modelNameLowerCamel}Service.fetchDetail(id);
        return CommonResult.success(details);
    }
}
